package battleship.AI;

import java.util.Random;

import battleship.PluginAI;
import battleship.PluginSetup;
import battleship.field.Field;
import battleship.loop.MoveCollisionException;
import battleship.loop.OutOfSpaceException;
import battleship.player.Player;
import battleship.setup.SetRandom;

public class BasicAI implements PluginAI{
	
	private int x;
	private int y;
	
	@Override
	public String getName() {
		return "easy";
	}

	@Override
	public String getDescription() {
		return "a bot striking purely random";
	}

	@Override
	public boolean attack(Player bot) {
		Random ranXY = new Random();
		
		boolean hit = false;
		boolean correct = false;
		while(!correct)
		{
			try {
				x = ranXY.nextInt(Field.getWidth());
				y = ranXY.nextInt(Field.getHeight());
				
				hit = bot.strike(y, x);
				correct = true;
			} catch (MoveCollisionException e) {
				correct = false;
			} catch (OutOfSpaceException e) {
				correct = false;
			}
		}
		
		return hit;
	}

	@Override
	public PluginSetup getSetupAlgorithm() {
		
		return new SetRandom();
	}
	
	@Override
	public int getX()
	{
		return x;
	}
	
	@Override
	public int getY()
	{
		return y;
	}


	
}
